Expand description
Simplified stable-compatible benchmark runner.
Almost all user code will only be interested in Bencher
and the
macros that are used to describe benchmarker functions and
the benchmark runner.
NOTE: There’s no proper black_box
yet in this stable port of the
benchmark runner, only a workaround implementation. It may not work
exactly like the upstream test::black_box
.
One way to use this crate is to use it as dev-dependency and setup
cargo to compile a file in benches/
that runs without the testing harness.
In Cargo.toml:
ⓘ
[[bench]]
name = "example"
harness = false
In benches/example.rs:
#[macro_use]
extern crate bencher;
use bencher::Bencher;
fn a(bench: &mut Bencher) {
bench.iter(|| {
(0..1000).fold(0, |x, y| x + y)
})
}
fn b(bench: &mut Bencher) {
const N: usize = 1024;
bench.iter(|| {
vec![0u8; N]
});
bench.bytes = N as u64;
}
benchmark_group!(benches, a, b);
benchmark_main!(benches);
Use cargo bench
as usual. A command line argument can be used to filter
which benchmarks to run.
Re-exports§
pub use self::TestFn::*;
Modules§
Macros§
- Defines a function called
$group_name
that returns the test description values for the listed functions$function
. - Define a
fn main()
that will run all benchmarks defined by the groups in$group_name
.
Structs§
- Manager of the benchmarking runs.
Enums§
Traits§
- Represents a benchmark function.
Functions§
- NOTE: We don’t have a proper black box in stable Rust. This is a workaround implementation, that may have a too big performance overhead, depending on operation, or it may fail to properly avoid having code optimized out. It is good enough that it is used by default.